<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "course".
 *
 * @property int $ID ID
 * @property int $XXID 学校ID
 * @property string $KCMC 课程名称
 * @property string $KCDM 课程代码
 * @property string $KCLB 课程类别
 * @property string $KCXZ 课程性质
 * @property string|null $KCJJ 课程简介
 * @property float $XF 学分
 * @property int $ZXS 总学时
 * @property int $LLXS 理论学时
 * @property int $SYXS 实验学时
 * @property int $SJXS 实践学时
 * @property string $KHFS 考核方式
 * @property string $JXDG 教学大纲
 * @property string $JC 教材
 * @property string $CJSJ 创建时间
 * @property string|null $GXSJ 更新时间
 *
 * @property School $xX
 * @property MajorCourse[] $majorCourses
 * @property Major[] $zies
 * @property TermCourse[] $termCourses
 * @property Term[] $xQs
 */
class Course extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'course';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['XXID', 'KCMC', 'KCDM', 'KCLB', 'KCXZ', 'XF', 'ZXS', 'LLXS', 'SYXS', 'SJXS', 'KHFS', 'JXDG', 'JC', 'CJSJ'], 'required'],
            [['XXID', 'ZXS', 'LLXS', 'SYXS', 'SJXS'], 'integer'],
            [['KCJJ'], 'string'],
            [['XF'], 'number'],
            [['CJSJ', 'GXSJ'], 'safe'],
            [['KCMC', 'KCDM', 'KCLB', 'KCXZ'], 'string', 'max' => 20],
            [['KHFS'], 'string', 'max' => 10],
            [['JXDG'], 'string', 'max' => 100],
            [['JC'], 'string', 'max' => 50],
            [['XXID'], 'exist', 'skipOnError' => true, 'targetClass' => School::className(), 'targetAttribute' => ['XXID' => 'ID']],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'ID' => 'ID',
            'XXID' => '学校ID',
            'KCMC' => '课程名称',
            'KCDM' => '课程代码',
            'KCLB' => '课程类别',
            'KCXZ' => '课程性质',
            'KCJJ' => '课程简介',
            'XF' => '学分',
            'ZXS' => '总学时',
            'LLXS' => '理论学时',
            'SYXS' => '实验学时',
            'SJXS' => '实践学时',
            'KHFS' => '考核方式',
            'JXDG' => '教学大纲',
            'JC' => '教材',
            'CJSJ' => '创建时间',
            'GXSJ' => '更新时间',
        ];
    }

    /**
     * Gets query for [[XX]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getXX()
    {
        return $this->hasOne(School::className(), ['ID' => 'XXID'])->inverseOf('courses');
    }

    /**
     * Gets query for [[MajorCourses]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getMajorCourses()
    {
        return $this->hasMany(MajorCourse::className(), ['KCID' => 'ID'])->inverseOf('kC');
    }

    /**
     * Gets query for [[Zies]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getZies()
    {
        return $this->hasMany(Major::className(), ['ID' => 'ZYID'])->viaTable('major_course', ['KCID' => 'ID']);
    }

    /**
     * Gets query for [[TermCourses]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getTermCourses()
    {
        return $this->hasMany(TermCourse::className(), ['KCID' => 'ID'])->inverseOf('kC');
    }

    /**
     * Gets query for [[XQs]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getXQs()
    {
        return $this->hasMany(Term::className(), ['id' => 'XQID'])->viaTable('term_course', ['KCID' => 'ID']);
    }
}
